﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Reflection;
using MoneyWentWhere.OutputHelpers;

namespace MoneyWentWhere.Utils
{
    public static class UglyExtensionMethods
    {
        readonly static char[] Delims = new char[] { '\r', '\n', ',', '"' }; 

        public static bool Sw(this String zis, String value)
        {
            return zis.StartsWith(value, StringComparison.InvariantCultureIgnoreCase);
        }

        public static String RemoveDelims(this String zis)
        {
            if (zis == null) { return zis; }

            foreach (char d in Delims)
            {
                zis = zis.Replace(d, ' ');
            }
            return zis;
        }

        public static String[] SplitLines(this String zis)
        {
            String[] nl = new String[] { Environment.NewLine };
            return zis.Split(nl, StringSplitOptions.None);            
        }

        public static String JoinLines(this IEnumerable<String> zis)
        {
            return zis.ToDisplayString(listFormat: "{0}", separator: "\r\n");            
        }

        public static String TrimOrPad(this String zis, int width, Alignment alignment)
        {
            if (width == 0) { return ""; }
            if (zis == null) { return new String(' ', width); }

            if (zis.Length > width) { zis = zis.Substring(0, width - 1) + ">"; }
            if (zis.Length < width)
            {
                if (alignment == Alignment.Left)
                {
                    return zis.PadRight(width);
                }
                else
                {
                    return zis.PadLeft(width);
                }
            }
            return zis;
        }
    }

    public enum Alignment { Left, Right }

}
